package com.neo.util;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.ShardedJedis;
import redis.clients.jedis.exceptions.JedisConnectionException;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

public class RedisUtils {

    /**
     * 拼装key
     * @param strings
     * @return
     */
    public static String key(String ...strings) {
        StringBuilder builder = new StringBuilder();
        if(strings != null) {
            for (String string : strings) {
                builder.append(string);
            }
        }
        return builder.toString();
    }



    public static Object  eval(String script, String key, String arg) {
        List<String> keys = new ArrayList<String>();
        keys.add(key);
        List<String> args = new ArrayList<String>();
        args.add(arg);

        ShardedJedis jedis = null;
        try {
            jedis = RedisClient.getRedisClient();
            Jedis j = jedis.getShard(key.getBytes());
            if(j != null) {
                return  j.eval(script, keys, args);
            }
        } catch (JedisConnectionException e) {
           // LOGGER.error("redis 链接异常: " + e.getMessage());
          //  counter();
        } catch (Exception e) {
          //  LOGGER.error("redis 异常: " + e.getMessage(), e);
        } finally {
            //jedis.returnRes(jedis);
        }
        return null;
    }


}
